package com.cisetech.web.bobocai.qiantai;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cisetech.service.ColumnService;
import com.cisetech.service.CodeService;
import com.cisetech.vo.Page;
import com.cisetech.vo.bobocai.CodeVo;
import com.cisetech.vo.bobocai.LContent;
import com.cisetech.vo.bobocai.LRegion;
import com.cisetech.vo.bobocai.QianTaiVo;

/**
 * 列表控制器
 * @author Administrator
 *
 */
@Controller
@RequestMapping(value="list")
public class ListController {
	
	@Autowired
	ColumnService columnService;
	@Autowired
	CodeService codeService;
	
	@RequestMapping(value="/type",method=RequestMethod.GET)
	public String list(QianTaiVo qianTaiVo,Model model,HttpServletRequest request,HttpServletResponse reponse) throws UnsupportedEncodingException{
		String  type = qianTaiVo.getType();
		model.addAttribute("type", type);
		if (qianTaiVo.getKeyword()!=null && !"".equals(qianTaiVo.getKeyword())){
			qianTaiVo.setKeyword(new String(qianTaiVo.getKeyword().getBytes("iso8859-1"),"utf-8")); 
		}
		model.addAttribute("qianTaiVo", qianTaiVo);
		if("0".equals(type)){//按行业分类
			CodeVo codeVo = new CodeVo();
			codeVo.setProductType("1");
			List<CodeVo> list = codeService.getlistss(codeVo);
			model.addAttribute("list", list);
			if("e".equals(request.getParameter("e"))){
				return "qiantai/e/industrylist";
			}
			return "qiantai/industrylist";
		}else if("1".equals(type)){//按地区分类
			String typediqu = request.getParameter("typediqu");
			if ("1".equals(typediqu)){
				if (request.getParameter("cCity")!=null && !"".equals(request.getParameter("cCity"))){
					String cCity = new String(request.getParameter("cCity").getBytes("iso8859-1"),"UTF-8");
					model.addAttribute("cCity", cCity);
				}
				if (request.getParameter("eCity")!=null && !"".equals(request.getParameter("eCity"))){
					String eCity = new String(request.getParameter("eCity").getBytes("iso8859-1"),"UTF-8");
					model.addAttribute("eCity", eCity);
				}	
				model.addAttribute("typediqu", typediqu);
				
			}
			if("e".equals(request.getParameter("e"))){
				return "qiantai/e/regionlist";
			}
			return "qiantai/regionlist";
		}else if("2".equals(type)){//按时间分类
			if("e".equals(request.getParameter("e"))){
				return "qiantai/e/datelist";
			}
			return "qiantai/datelist";
		}else{//剩余一切按关键词分类
			if("e".equals(request.getParameter("e"))){
				return "qiantai/e/keywordlist"; 
			}
			return "qiantai/keywordlist";
		}
	}
	@ResponseBody
	@RequestMapping(value="/getList",method=RequestMethod.POST)
	public Page<LContent> getList(LContent content,HttpServletRequest request,HttpServletResponse reponse){
		Page<LContent> page = columnService.getList(content);
		return page;
		
	}
	@RequestMapping(value="/getTypeList",method=RequestMethod.GET)
	public String getTypeList(LContent content,Model model,HttpServletRequest request,HttpServletResponse reponse){
		model.addAttribute("codeCode", content.getCode());
		if ("e".equals(request.getParameter("e"))){
			return "qiantai/e/industrylists";
		}
		return "qiantai/industrylists";
		
	}
	@ResponseBody
	@RequestMapping(value="/getTypeLists",method=RequestMethod.POST)
	public Page<LContent> getTypeLists(LContent content,HttpServletRequest request,HttpServletResponse reponse){
 		Page<LContent> page = columnService.getList(content);
		return page;
		
	}
	@ResponseBody
	@RequestMapping(value="/region/getlist",method=RequestMethod.POST)
	public List<QianTaiVo> getRegionList(QianTaiVo qianTaiVo,HttpServletRequest request,HttpServletResponse reponse){
		List<QianTaiVo> list = new ArrayList<QianTaiVo>();
		if("请选择".equals(qianTaiVo.getcState())){
			qianTaiVo.setcState("");
		}
		if("请选择".equals(qianTaiVo.getcCountry())){
			qianTaiVo.setcCountry("");
		}
		list = columnService.getRegionList(qianTaiVo);
		return list;
	}
	
	@RequestMapping(value="/indexList",method=RequestMethod.POST)
	public String indexList(QianTaiVo qianTaiVo,Model model,HttpServletRequest request,HttpServletResponse reponse){
		model.addAttribute("qianTaiVo", qianTaiVo);
		String e = request.getParameter("e");
		if ("e".equals(e)){
			return "qiantai/e/indexList";
		}
		return "qiantai/indexList";
		
	}
	@ResponseBody
	@RequestMapping(value="/getIndexList",method=RequestMethod.POST)
	public Page<LContent> getIndexList(LContent content,HttpServletRequest request,HttpServletResponse reponse){
 		Page<LContent> page = columnService.getList(content);
		return page;
		
	}
}
